/**
 * @author yuyangyang
 * @time 2015/3/2
 */

define(function (require) {
    var angular = require('angular');

    angular.module('services', [])
        .factory('sportService', function ($http) {
            return {
                getList: function (callback) {
                    $http.get('/sport/')
                        .success(callback);
                },
                getItem: function (sportId, callback) {
                    $http.get('/sport/' + sportId)
                        .success(callback);
                },
                addSport: function (sport, callback) {
                    $http.post('/sport/new', sport)
                        .success(callback);
                }
            };
        })

        .factory('meetService', function ($http) {
            return {
                getList: function (sportId, callback) {
                    $http.get('/meet/' + sportId)
                        .success(callback);
                },
                getItem: function (meetId, callback) {
                    $http.get('/meet/detail/' + meetId)
                        .success(callback);
                },
                addMeet: function (meet, callback) {
                    $http.post('/meet/new', meet)
                        .success(callback);
                }
            };
        })

        .factory('userService', function ($http) {
            return {
                getMessage: function (callback) {
                    $http.get('/user/owner')
                        .success(callback);
                }
            };
        })

        .factory('ownerService', function ($http) {
            return {
                getMessage: function (callback) {
                    $http.get('/user/owner')
                        .success(callback);
                },
                register: function (owner, callback) {
                    $http.post('/user/register', owner)
                        .success(callback);
                },
                login: function (owner, callback) {
                    $http.post('/user/login', owner)
                        .success(callback);
                },
                logout: function (callback) {
                    $http.get('/user/logout')
                        .success(callback);
                }
            };
        })

        .factory('joinService', function ($http) {
            return {
                addJoin: function (params, callback) {
                    $http.post('/join/new', params)
                        .success(callback);
                },
                getMessage: function (params, callback) {
                    $http.get('/join/message?' + 'meet=' + params.meet)
                        .success(callback);
                },
                cancel: function (params, callback) {
                    $http.post('/join/cancel', params)
                        .success(callback);
                }
            };
        });
});
